package com.wishwall.web.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter(urlPatterns={"/rest/ei/*"})
public class EIRequestWebFilterChain implements Filter {

	private AbstractFilter firstFilter = null;

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {

		try {
			firstFilter.doFilter(request, response, chain);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServletException(e);
		}
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		firstFilter = new RequestIDFilter();
		PersistenceContextFilter persistenceContextFilter = new PersistenceContextFilter();
		RestSecurityFilter restSecurityFilter = new RestSecurityFilter();

		firstFilter.setNextFilter(persistenceContextFilter);
		persistenceContextFilter.setNextFilter(restSecurityFilter);
	}

}
